package com.yang.demo.adapter;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yang.demo.DataBean;
import com.yang.demo.R;
import com.yang.demo.util.rxbus.RxBus;
import com.yang.demo.view.TagsAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by moxun on 16/1/19.
 */
public class TextTagsAdapter4 extends TagsAdapter {

    private List<String> dataSet = new ArrayList<>();
    private int colors;

    private Context context;

    public TextTagsAdapter4(Context context, int colors, List<String> data) {
        this.context = context;
        this.colors = colors;
        this.dataSet = data;
    }

    @Override
    public int getCount() {
        return dataSet.size();
    }

    @Override
    public View getView(final Context context, final int position, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.tag_item_view2, parent, false);
        TextView tv = view.findViewById(R.id.text);
        View v = view.findViewById(R.id.view);
        GradientDrawable gradientDrawable = (GradientDrawable) v.getBackground();
        gradientDrawable.setColor(ContextCompat.getColor(context, colors));
        tv.setTextColor(ContextCompat.getColor(context, colors));
        tv.setText(dataSet.get(position));
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //点击了作品
                DataBean bean = new DataBean(position,dataSet.get(position), colors);
                RxBus.get().send(1004, bean);
            }
        });
        return view;
    }

    @Override
    public Object getItem(int position) {
        return dataSet.get(position);
    }

    @Override
    public int getPopularity(int position) {
        return position % 7;
    }

    @Override
    public void onThemeColorChanged(View view, int themeColor) {
        view.setBackgroundColor(themeColor);
    }
}